﻿<%@ Page Title="" Language="C#" MasterPageFile="~/SiteJN.Master" AutoEventWireup="true" CodeBehind="cx.aspx.cs" Inherits="jnagr.Web.sicpet.cx" %>

<%@ Register Src="~/Controls/checkright.ascx" TagPrefix="uc1" TagName="checkright" %>
<%@ Register Src="~/Controls/spet.ascx" TagPrefix="uc1" TagName="spet" %>
<%@ Register Src="~/Controls/copyright.ascx" TagPrefix="uc1" TagName="copyright" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <script type="text/javascript">
        var sprovince = "";
        var scity = "";
        var scounty = "";
        var areas = "";
        var se = "";
        var sebm = "";
        var getdata = "";
        var level;
        var markerClusterer;
        var markers = [];
        var devid;
        var pt;
        var map;
        var data_info;
        var opts;
        var StartTime;
        var EndTime;
        $(function () {
            curmenu('孢子动态');
            $.ajax({
                type: "post",
                dataType: "json",
                url: "../admin/getinfo.ashx?action=level",
                success: function aa(data) {
                    sprovince = data[0].province;
                    scity = data[0].city;
                    scounty = data[0].county;
                    InitTree();
                    InitMap();
                }
            });
        });
        
        function InitMapmark() {
            $('#win').datagrid({
                //title: '测报点列表', //表格标题
                url: '../devinfo/GetDev.ashx', //请求数据的页面
                sortName: 'mname', //排序字段
                idField: 'mid', //标识字段,主键
                iconCls: '', //标题左边的图标
                width: '95%', //宽度
                height: '95%', //高度
                nowrap: false, //是否换行，True 就会把数据显示在一行里
                striped: true, //True 奇偶行使用不同背景色
                collapsible: false, //可折叠
                sortOrder: 'desc', //排序类型
                remoteSort: true, //定义是否从服务器给数据排序
                fitColumns: true,
                singleSelect: true,
                method: 'post',
                columns: [[
	                { title: '测报站名', field: 'mname', width: 80, sortable: true }
                ]],
                toolbar: "#tab_toolbar",
                queryParams: { "action": "querydev", "dtype": "BPY" },
                pageNumber: 1, //默认索引页
                pageSize: 500, //默认一页数据条数
                rownumbers: true, //行号
                pageList: [10, 20, 50, 200, 500],
                pagination: false, //是否开启分页                
                onLoadSuccess: function (data) {
                    data_info = [];
                    getdata = data;
                    map.clearOverlays();
                    $.each(data.rows, function (k, v) {
                        data_info.push({ "lng": v["mjd"], "lat": v["mwd"], "mlevel": v["DevType"], "mname": v["devname"], "madd": v["DevLocation"], "mpic": v["mpic"], "devid": v["DevID"] });
                    });
                    var mlevel;
                    var marker;
                    var ptt = "";
                    if (markers.length > 0) {
                        if (markerClusterer != null) {
                            markerClusterer.removeMarkers(markers);
                            markerClusterer = null;
                        }
                        markers = [];
                    }
                    for (var i = 0; i < data_info.length; i++) {
                        mlevel = data_info[i].mlevel;
                        ptt = new BMap.Point(data_info[i].lng, data_info[i].lat);
                        if (mlevel == 'CBD')
                            marker = new BMap.Marker(ptt, { icon: icon4 });
                        else if (mlevel == 'YBQ')
                            marker = new BMap.Marker(ptt, { icon: icon3 });
                        else if (mlevel == 'XQH')
                            marker = new BMap.Marker(ptt, { icon: icon2 });
                        else
                            marker = new BMap.Marker(ptt, { icon: icon1 });

                        var did = data_info[i].devid;
                        map.addOverlay(marker);
                        label = new BMap.Label(data_info[i].mname, { offset: new BMap.Size(20, -10) });
                        marker.setLabel(label);
                        markers.push(marker);
                        addClickHandler(did, marker);
                    }
                    if (markers.length > 0)
                        markerClusterer = new BMapLib.MarkerClusterer(map, { markers: markers });//对地图扩大缩小后会都所有的点全显示出来。
                    if (scounty != "")
                        map.centerAndZoom(scounty, 12);
                    else if (scity != "")
                        map.centerAndZoom(scity, 10);
                    else if (sprovince != "")
                        map.centerAndZoom(sprovince, 8);
                    else
                        map.centerAndZoom("西安", 5);
                    if (areas != "")
                        getBoundary(areas);
                    renderstation();
                }
            });
        }
        function addClickHandler(did, marker) {
            marker.addEventListener("click", function (e) {
                showawsinfectInfo(did);

            }
            );
        }
        function InitTree() {
            $('#pt').tree({
                width: '100%', //宽度 
                lines: true,
                //data: provincetree,   
                url: '../areainfo/GetArea.ashx', //请求数据的页面 
                method: 'post',
                queryParams: { "action": "querymyareauser" },
                onBeforeExpand: function (node) {
                    $("#pt").tree("options").queryParams = { "action": "queryyb" };
                    $('#pt').tree('options').url = "../areainfo/GetArea.ashx?pid=" + node.id;
                },
                onClick: function (node) {
                    if (node.text != "") {
                        sebm = node.bm;
                        //获取地区全称
                        if (sebm == "0")
                            areas = "";
                        else if (sebm.length == 6 && sebm.indexOf("0000")) {
                            areas = node.text;
                        }
                        else {
                            var result = $.ajax({
                                url: "../areainfo/GetArea.ashx?action=queryarea",
                                type: 'post',
                                dataType: 'json',
                                async: false,
                                cache: false
                            }).responseText;
                            areas = result;
                        }
                        reloadgridTree();
                    }

                },
                onLoadSuccess: function (node, param) {

                }
            });
        }
        function showawsinfectInfo(id) {
            devid = id;
            addTab(devid, 'mycx.html');
        }
        function InitGird() {
            var h = $("#my1").height();
            var w = $("#my1").width();
            $('#mtgrid').datagrid({
                title: '孢子动态', //表格标题
                url: 'GetBPY.ashx', //请求数据的页面
                sortName: 'updatetime', //排序字段
                idField: 'cxid', //标识字段,主键
                iconCls: '', //标题左边的图标
                height: h,
                width: w,
                nowrap: false, //是否换行，True 就会把数据显示在一行里
                striped: true, //True 奇偶行使用不同背景色
                collapsible: false, //可折叠
                sortOrder: 'desc', //排序类型
                remoteSort: true, //定义是否从服务器给数据排序
                fitColumns: true,
                singleSelect: true,
                method: 'post',
                columns: [[
                   { title: '区域', field: 'DevLocation', width: 150, sortable: true },
                    { title: '监测人', field: 'uname', width: 80 },
                    { title: '监测点', field: 'devname', width: 100 },
                    { title: '信息', field: 'infos', width: 250 },
                    {
                        title: '上报时间', field: 'updatetime', width: 200, formatter: function (value, row, index) {
                            if (value != "") {
                                if (value.indexOf("-") != -1)
                                    value = value.replace(/-/g, "/")
                                return new Date(value).pattern("yyyy年M月d日");
                            }
                        }
                    },
                    {
                        title: '查看图像', field: 'cz', width: 60, formatter: function (value, row, index) {
                            return '<a href="#" onclick="showpic(\'' + row.uppic + '\');">查看</a>';
                            }
                    }
                ]],
                onClickRow: function (rowIndex, rowData) {                    
                    $('#mmark').val(rowData.infos + '<img src="' + rowData.uppic + '"></img>');                                           
                },
                toolbar: "#tab_toolbars",
                queryParams: { "action": "query", "devid": devid, "StartTime": StartTime, "EndTime": EndTime },//
                pagination: true, //是否开启分页
                pageNumber: 1, //默认索引页
                pageSize: 20, //默认一页数据条数
                rownumbers: true
            });

        }
        function getQueryParams(queryParams) {
            StartTime = $("#StartTime").datebox("getValue");
            EndTime = $("#EndTime").datebox("getValue");
            queryParams.StartTime = StartTime;
            queryParams.EndTime = EndTime;
            return queryParams;

        }
        //增加查询参数，重新加载表格  
        function reloadgrid() {
            var queryParams = $('#mtgrid').datagrid('options').queryParams;
            getQueryParams(queryParams);
            $('#mtgrid').datagrid('options').queryParams = queryParams;
            $("#mtgrid").datagrid('reload');

        }
        function showpic(url)
        {
            
            $('#picwin').window({
                width: 900,
                height: 550,
                modal: true,
                title: '图片显示',
                closed: false
            }).window('center');
            $('#showuppic').attr('src',url);
        }
        function showxc() {
            year = new Date().getFullYear();
            $('#jd').combobox({
                onSelect: function (newValue, oldValue) {
                    if (newValue.text == '一季度') {
                        $("#StartTime").datebox("setValue", year + "-1-1");
                        $("#EndTime").datebox("setValue", year + "-3-31");
                    }
                    else if (newValue.text == '二季度') {
                        $("#StartTime").datebox("setValue", year + "-4-1");
                        $("#EndTime").datebox("setValue", year + "-6-30");
                    }
                    else if (newValue.text == '三季度') {
                        $("#StartTime").datebox("setValue", year + "-7-1");
                        $("#EndTime").datebox("setValue", year + "-9-30");
                    }
                    else if (newValue.text == '四季度') {
                        $("#StartTime").datebox("setValue", year + "-10-1");
                        $("#EndTime").datebox("setValue", year + "-12-31");
                    }
                    else if (newValue.text == '当天') {
                        var curr_time = new Date();
                        var tc_time = new Date(curr_time.getTime() + 24 * 60 * 60 * 1000);
                        var strDate = curr_time.getFullYear() + "-";
                        strDate += curr_time.getMonth() + 1 + "-";
                        strDate += curr_time.getDate();
                        var strDateend = tc_time.getFullYear() + "-";
                        strDateend += tc_time.getMonth() + 1 + "-";
                        strDateend += tc_time.getDate();
                        $("#StartTime").datebox("setValue", strDate);
                        $("#EndTime").datebox("setValue", strDateend);
                    }
                }
            });
            var curr_time = new Date();
            var tc_time = new Date(curr_time.getTime() + 24 * 60 * 60 * 1000);
            var strDate = curr_time.getFullYear() + "-";
            strDate += curr_time.getMonth() + 1 + "-";
            strDate += curr_time.getDate();
            var strDateend = tc_time.getFullYear() + "-";
            strDateend += tc_time.getMonth() + 1 + "-";
            strDateend += tc_time.getDate();

            $("#StartTime").datebox("setValue", strDate);
            $("#EndTime").datebox("setValue", strDateend);
            StartTime = $("#StartTime").datebox("getValue");
            EndTime = $("#EndTime").datebox("getValue");
            $('#adddevid').val(devid);
            InitGird();
            $("#yjfx").panel({
                href: '../html/alarmall.html',
                title: '孢子预警',
                tools: [{ iconCls: 'icon-phone', handler: function () { sendAlarm('虫情预警'); } }],
                onLoad: function () {
                    InitSendUser();
                    $("#btnyj").click(function () {
                        sendAlarm('虫情预警');
                    });
                }

            });
           
        }
        function newUser() {           
            //清空内容  
            $('#fm').form('clear');          
            $('#adddevid').val(devid);           
            $('#dlg').dialog('open').dialog('setTitle', '添加');            
        }

        function savedata() {
            $.messager.progress();
            var f = $('#fm');
            f.form('submit', {
                url: "GetBPY.ashx?action=add",
                onSubmit: function () {
                    return $(this).form('validate');
                },
                success: function (result) {
                    $.messager.progress('close');
                    if (result.indexOf("T") == 0) {
                        f.form('clear');
                        $('#adddevid').val(devid);
                        $('#dlg').dialog('close');
                        $.messager.alert("提示", "恭喜您，信息添加成功", "info");
                        $('#mtgrid').datagrid('reload');
                    }
                    else if ((result.indexOf("F") == 0)) {
                        $.messager.alert("提示", "添加失败，请重新操作！", "info");
                        return;
                    }
                    else if ((result.indexOf("L") == 0)) {
                        $.messager.alert("提示", "长时间没有操作，请重新登录！", "info");
                        top.location = '/index.aspx';
                        return;
                    }
                }
            });
        }
        function remove() {
            var row = $('#mtgrid').datagrid('getSelected');
            if (row == null) {
                $.messager.alert("提示", "请选择要删除的行！", "info");
            }
            if (row) {
                $.messager.confirm('提示', '你确定要删除这条信息吗？', function (r) {
                    if (r) {
                        $('#fm').form('submit', {
                            url: 'GetBPY.ashx?cxid=' + row.cxid + "&action=delete",
                            onSubmit: function () {
                                //return $(this).form('validate');  
                            },
                            success: function (result) {
                                if (result.indexOf("T") == 0) {
                                    $('#dlg').dialog('close');
                                    $('#mtgrid').datagrid('clearSelections'); //清空选中的行  
                                    $.messager.alert("提示", "恭喜您，信息删除成功！", "info");
                                    $('#mtgrid').datagrid('reload');
                                }
                                else {
                                    $.messager.alert("提示", "删除失败，请重新操作！" + result, "info");
                                    return;
                                }

                            }

                        });
                    }
                })
            }
        }

        function AutoResizeImage(maxWidth, maxHeight, objImg) {
            var img = new Image();
            img.src = objImg.src;
            var hRatio;
            var wRatio;
            var Ratio = 1;
            var w = img.width;
            var h = img.height;
            wRatio = maxWidth / w;
            hRatio = maxHeight / h;
            if (maxWidth == 0 && maxHeight == 0) {
                Ratio = 1;
            } else if (maxWidth == 0) { //
                if (hRatio < 1) Ratio = hRatio;
            } else if (maxHeight == 0) {
                if (wRatio < 1) Ratio = wRatio;
            } else if (wRatio < 1 || hRatio < 1) {
                Ratio = (wRatio <= hRatio ? wRatio : hRatio);
            }
            if (Ratio < 1) {
                w = w * Ratio;
                h = h * Ratio;
            }
            objImg.height = h;
            objImg.width = w;
        }
    </script>

    <script id="tmpstations" type="text/html">
        {{each rows as value index}}
        <div class="stations">
            <div class="level1Div" onclick="showawsinfectInfo('{{value.DevID}}')">
                <div class="levelsb">{{value.devname}}</div>
                <div class="leveltime">时间：{{value.mdatetime}} 已运行{{value.days}}天</div>
                <div class="levelbottom">
                    <div class="levelbtn">详细</div>
                </div>
            </div>
        </div>
        {{/each}} 
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <div id="mainDiv">
        <uc1:checkright runat="server" ID="checkright" />
        <uc1:spet runat="server" ID="spet" />
        <div>
            <div id="contentDiv">
                <div class="mypt">
                    <ul id="pt"></ul>
                </div>
                <div id="mycontent">
                    <div id="tab" class="easyui-tabs">
                        <div title="GSI" style="padding: 5px;">

                            <div style="position: relative;">
                                <div id="mymap"></div>
                                <div id="Maptype" style="height: 87px; width: 130px; position: absolute; float: left; margin-left: 850px; top: 50px; z-index: 99; color: Black; border-bottom-left-radius: 5px; border-bottom-right-radius: 5px; border-top-left-radius: 5px; border-top-right-radius: 5px;">
                                    <input id="CBstationname" onclick="ShowstationName('checkbox')" checked="checked" style="float: left; margin-left: 10px;"
                                        type="checkbox" />
                                    <label onclick="ShowstationName('label')" style="height: 20px; width: 100px; float: left; text-align: left; font-size: 13px; font-family: 宋体; font-weight: bold; margin-top: 3px; cursor: pointer;">
                                        显示名称</label>
                                </div>
                            </div>

                        </div>
                        <div title="设备列表" style="overflow: auto; padding: 5px;">
                            <div id="mystations"></div>
                        </div>
                    </div>
                </div>
            </div>
            <uc1:copyright runat="server" ID="copyright" />
        </div>
    </div>
    
    <div id="picwin" class="easyui-window" data-options="iconCls:'icon-save',modal:true,closed:true">
        <div class="easyui-layout" data-options="fit:true">
            <div data-options="region:'center'" style="padding: 5px; background: #eee;">
                <img id="showuppic" onload='AutoResizeImage(880,490,this)' />
            </div>
        </div>
    </div>
     <div id="dlg" class="easyui-dialog" style="width: 400px; height: auto; padding: 10px 20px"
        data-options="closed:true,buttons:'#dlg-buttons',shadow:false">       
        
        <form id="fm" method="post" enctype="multipart/form-data">

             <div class="fitem" style="height:auto;width:350px;">
                                <label>图片：</label>
                                <input id="File1" name="tpic" type="file" style="width: 250px;" />
                                <input id="mpic" name="mpic" type="hidden" />
                            </div>           
            <div class="fitem" style="height:auto;width:350px;">
                <label>备注：</label>               
                                <input name="adddevid" id="adddevid" type="hidden" />
                <textarea id="remark" name="remark" style="width: 250px;"></textarea>
            </div>
            <div style="clear: both;"></div>
        </form>
    </div>
    <div id="dlg-buttons">
        <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-ok'" onclick="savedata()">保存</a>
        <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" onclick="javascript:$('#dlg').dialog('close')">关闭</a>
    </div>
</asp:Content>

